﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: LGPL, Software Libre	*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System;
using System.Xml;
using System.Collections.Generic;

using ESF.General;

#endregion


namespace ESF.Object.XmlRepresenter.Rules
{
	public sealed class UniqueRule : IEquatable<UniqueRule>
	{
		#region Miembros
		
		private string _Name;
		
		private List<XmlMember> _Members;
		
		#endregion
		
		
		#region Propiedades
		
		public string Name { get { return this._Name; } }
		
		
		public List<XmlMember> Members { get { return this._Members; } }
				
		
		public string MembersCSV
		{
			get
			{
				string strResult;
				
				
				strResult = string.Empty;
				
				foreach (XmlMember strMemberName in this._Members)
				{
					strResult += strMemberName + ",";
				}
				
				return strResult.Substring (0, strResult.Length - 1);
			}
		}
		
		#endregion
		
		
		#region Constructor
		
		public UniqueRule (ref XmlObject pobjObject, ref XmlTextReader pxmlReader)
		{
			string strMembersCSV;
			
			XmlHelper xmlEx;
			
			
			xmlEx = new XmlHelper ();
			xmlEx.EvaluatedNodeReader = pxmlReader;
			xmlEx.ObjectName = "UniqueRule";
			
			this._Name = xmlEx.GetAttributeValue (true, "name", "Nombre");
			
			strMembersCSV = xmlEx.GetAttributeValue (true, "members", "Nombres de los Miembros");
			
			this._Members = new List<XmlMember> ();
						
			foreach (string strMemberName in strMembersCSV.Replace (" ", string.Empty).Split (','))
			{
				this._Members.Add (pobjObject [strMemberName]);
			}
		}
		
		#endregion
		
		
		#region Funciones
		
		public void ToXml (ref XmlTextWriter pxmlWriter)
		{
			pxmlWriter.WriteStartElement ("Unique");
						
			pxmlWriter.WriteAttributeString ("name", this._Name);
			pxmlWriter.WriteAttributeString ("members", this.MembersCSV);
			
			pxmlWriter.WriteEndElement ();
		}
		
		#endregion


		#region IEquatable<UniqueRule> Members

		public bool Equals(UniqueRule pobjOther)
		{
			return (this._Name == pobjOther.Name);
		}

		#endregion
	}
}